package com.hbnu.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hbnu.mapper.PetMapper;
import com.hbnu.pojo.Pet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PetService {

    @Autowired
    private PetMapper petMapper;
    //  通过用户id查询所有宠物
    public List<Pet> getPetsByOwnerId(Integer ownerId) {
        return petMapper.selectList(new QueryWrapper<Pet>().eq("owner_id", ownerId));
    }
    //查询所有宠物
    public List<Pet> getAllPets() {
        return petMapper.selectList(null);
    }


    // 添加宠物
    public boolean addPet(Pet pet) {
        return petMapper.insert(pet) > 0;
    }

    //  删除宠物
    public boolean deletePet(Integer petId) {
        return petMapper.deleteById(petId) > 0;
    }

    //  更新宠物信息
    public boolean updatePet(Pet pet) {
        return petMapper.updateById(pet) > 0;
    }
}
